//
//  Header.m
//  Utils
//
//  Created by enghou on 2018/6/12.
//  Copyright © 2018年 xyxorigation. All rights reserved.
//

#import "Header.h"

@interface Header()

@property(nonatomic,strong)UIImageView *arrowImage;

@property(nonatomic,strong)UILabel *titleLabel;

@end

@implementation Header
-(NSArray <LevelItemModel *> *)selectedLevel{
    return nil;
}



- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        CGFloat w = [UIScreen mainScreen].bounds.size.width;
        self.arrowImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, (44 - 8) / 2, 15, 8)];
        self.arrowImage.image = [UIImage imageNamed:@"icon_down"];
        [self.contentView addSubview:self.arrowImage];
        
        UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, w, 44)];
        [button addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:button];
        
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, (44 - 20) / 2, w-20, 20)];
        self.titleLabel.font = [UIFont systemFontOfSize:17];
        self.titleLabel.textColor = [UIColor blackColor];
        
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 43, w, 1)];
        line.backgroundColor = [UIColor darkGrayColor];
        [self.contentView addSubview:line];
        
        [self.contentView addSubview:self.titleLabel];
    }
    return self;
}

-(void)btnClick:(UIButton *)btn{
    self.model.isExpand = ! self.model.isExpand;
    if (self.model.isExpand) {
        self.arrowImage.transform = CGAffineTransformIdentity;
    }else{
        self.arrowImage.transform = CGAffineTransformMakeRotation(M_PI);
    }
    if (self.clickBlock) {
        self.clickBlock(self.model.isExpand);
    }
}

- (void)setModel:(LevelItemModel *)model{
    if (_model != model) {
        _model = model;
    }
    self.titleLabel.text = model.orgType;
    if (model.isExpand) {       //展开
        self.arrowImage.transform = CGAffineTransformIdentity;
    }else{
        self.arrowImage.transform = CGAffineTransformMakeRotation(M_PI);
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
